package br.com.duduso.conferencia_claro_desktop.model;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JComboBox;

/**
 *
 * @author duduso
 */
public class ComboBox<T> extends JComboBox{

    private List<T> values;

    public ComboBox() {
            this.values = new ArrayList<T>();
    }

    public void addItem(String label, T value){
            addItem(label);
            this.values.add(value);
    }

    public void removerItem(T value){
            int index = this.values.indexOf(value);
            remove(index);
            this.values.remove(value);
    }

    @Override
    public void removeItemAt(int index){
            super.removeItemAt(index);
            this.values.remove(values.get(index));
    }

    @Override
    public T getItemAt(int index) {
            return this.values.get(index);
    }

    @Override
    public T getSelectedItem() {
            return this.values.get(getSelectedIndex());
    }

    @Override
    public void removeAllItems() {
            super.removeAllItems();
            this.values.clear();
    }

    @Override
    public int getItemCount() {
            return this.values.size();
    }

    @Override
    @Deprecated
    public void addItem(Object anObject) {
            super.addItem(anObject);
    }

    @Override
    @Deprecated
    public Object[] getSelectedObjects() {
            return super.getSelectedObjects();
    }

}
